package com.rongke.utils;

import java.util.concurrent.ThreadLocalRandom;

/**
 * userId生成器
 * 
 * @author Administrator
 *
 */
public class UserIdGenerator {
	private static final ThreadLocalRandom ra = ThreadLocalRandom.current();

	/**
	 * UserId生成规则 {固定前缀'U'}{yyyyMMddHHmmssSSS}{预留4位0000}{4位随机数}
	 * 
	 * @return
	 */
	public static String getNewUserId() {
		StringBuilder sb = new StringBuilder();
		sb.append('U');
		sb.append(DateUtils.getCurrentTime());
		sb.append("0000");
		sb.append(getUserIdRandomPart());
		return sb.toString();
	}

	private static String getUserIdRandomPart() {
		int randomNum = ra.nextInt(9999);
		String result = "0000" + randomNum;
		result = result.substring(result.length() - 4);
		return result;
	}

	// public static void main(String[] args) {
	// System.out.println(getNewUserId());
	// }
}